// package com.zmn.oms.task.es.business.impl.orderpay;
//
// import com.alibaba.fastjson.JSON;
// import com.google.common.collect.Lists;
// import com.zmn.common.utils.collection.CollectionUtil;
// import com.zmn.common.utils.reflect.BeanMapper;
// import com.zmn.common.utils.string.StringUtil;
// import com.zmn.oms.model.entity.pay.OrderPay;
// import com.zmn.oms.model.entity.warranty.OrderWarranty;
// import com.zmn.oms.model.entity.work.OrderWork;
// import com.zmn.oms.model.es.EsOrderPay;
// import com.zmn.oms.model.vo.order.EsOrderDetailVO;
// import com.zmn.oms.services.interfaces.detail.OrderDetailService;
// import com.zmn.oms.services.interfaces.orderpay.EsOrderPayService;
// import com.zmn.oms.services.interfaces.pay.OrderPayService;
// import com.zmn.oms.services.interfaces.work.OrderWorkService;
// import com.zmn.oms.task.es.business.interfaces.orderpay.SyncEsOrderPayBService;
// import com.zmn.pay.common.constant.PayConsts;
// import lombok.extern.slf4j.Slf4j;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.stereotype.Service;
//
// import java.util.ArrayList;
// import java.util.List;
// import java.util.Map;
// import java.util.Set;
// import java.util.stream.Collectors;
//
// /**
//  * 类描述：同步工单支付凭证
//  *
//  * @author wangxiaokun
//  * @since 2021/05/08 17:27
//  */
// @Service
// @Slf4j
// public class SyncEsOrderPayBServiceImpl implements SyncEsOrderPayBService {
//
//     @Autowired
//     private OrderPayService orderPayService;
//     @Autowired
//     private OrderWorkService orderWorkService;
//     @Autowired
//     private OrderDetailService orderDetailService;
//     @Autowired
//     private EsOrderPayService esOrderPayService;
//
//     @Override
//     public void sync(List<Long> orderIdList) {
//
//         log.debug("#orderpaychange# sync start orderId list : {}", JSON.toJSONString(orderIdList));
//         if (CollectionUtil.isNullOrEmpty(orderIdList)) {
//             return;
//         }
//
//         // 支付凭证集合
//         List<OrderPay> orderPayList = orderPayService.listEsOrderPayByOrderIdList(orderIdList);
//         if (CollectionUtil.isNullOrEmpty(orderPayList)) {
//             log.debug("#orderPayChange# 工单没有支付凭证");
//             return;
//         }
//
//         // 订单详情集合
//         List<EsOrderDetailVO> orderDetailList = orderDetailService.listEsOrderDetailByOrderIdList(orderIdList);
//         if (CollectionUtil.isNullOrEmpty(orderDetailList)) {
//             log.error("#orderpaychange# sync fail, not found orderDetailList, orderId list : {}", JSON.toJSONString(orderIdList));
//             return;
//         }
//
//         // 订单集合
//         List<OrderWork> orderWorkList = orderWorkService.listEsOrderWorkByOrderIdList(orderIdList);
//         if (CollectionUtil.isNullOrEmpty(orderDetailList)) {
//             log.error("#orderpaychange# sync fail, not found orderWorkList, orderId list : {}", JSON.toJSONString(orderIdList));
//             return;
//         }
//
//         Map<Long, EsOrderDetailVO> orderDetailMap = orderDetailList.stream().collect(Collectors.toMap(EsOrderDetailVO::getDetailId, EsOrderDetailVO -> EsOrderDetailVO));
//         Map<Long, OrderWork> orderWorkMap = orderWorkList.stream().collect(Collectors.toMap(OrderWork::getWorkId, OrderWork -> OrderWork));
//
//         List<EsOrderPay> esOrderPayList = Lists.newArrayListWithExpectedSize(orderPayList.size());
//
//         // 组装支付凭证
//         orderPayList.forEach(orderPay -> {
//             EsOrderPay esOrderPay = BeanMapper.map(orderPay, EsOrderPay.class);
//             esOrderPay.setId(orderPay.getOrderPayId());
//             esOrderPay.setOrderId(orderPay.getOrderId());
//             esOrderPay.setWorkId(orderPay.getWorkId());
//             esOrderPay.setPayChannelName(PayConsts.getPayChannelName(esOrderPay.getPayChannelId()));
//             esOrderPay.setPayTargetChannelName(PayConsts.getPayChannelName(esOrderPay.getPayTargetChannelId()));
//
//             // 组装工单数据
//             this.processOrderWork(orderWorkMap, esOrderPay);
//
//             // 组装工单详情数据
//             this.processOrderDetail(orderDetailMap, esOrderPay);
//
//             esOrderPayList.add(esOrderPay);
//         });
//
//         esOrderPayService.saveAll(esOrderPayList);
//         log.debug("#orderpaychange# sync end orderId list : {}", JSON.toJSONString(orderIdList));
//     }
//
//     /**
//      * 组装工单数据
//      *
//      * @param orderWorkMap
//      * @param esOrderPay
//      */
//     private void processOrderWork(Map<Long, OrderWork> orderWorkMap, EsOrderPay esOrderPay) {
//         OrderWork orderWork = orderWorkMap.get(esOrderPay.getWorkId());
//
//         esOrderPay.setOrderType(orderWork.getType());
//         esOrderPay.setCodeEnd6(StringUtil.cutEnd(esOrderPay.getWorkId().toString(), 6));
//         esOrderPay.setPlat(orderWork.getPlatWork());
//         esOrderPay.setCompanyId(orderWork.getCompanyId());
//         esOrderPay.setCompanyName(orderWork.getCompanyName());
//         esOrderPay.setCityId(orderWork.getCityId());
//         esOrderPay.setServCategId(orderWork.getServCategId());
//
//         esOrderPay.setOrgOneId(orderWork.getOrgOneId());
//         esOrderPay.setOrgTwoId(orderWork.getOrgTwoId());
//         esOrderPay.setOrgThreeId(orderWork.getOrgThreeId());
//         esOrderPay.setOrgFourId(orderWork.getOrgFourId());
//         esOrderPay.setChannelOneId(orderWork.getChannelOneId());
//         esOrderPay.setChannelTwoId(orderWork.getChannelTwoId());
//         esOrderPay.setChannelId(orderWork.getChannelId());
//         esOrderPay.setChannelName(orderWork.getChannelName());
//         esOrderPay.setBizType(orderWork.getBizType());
//
//         esOrderPay.setCompleteTime(orderWork.getCompleteTime());
//         esOrderPay.setCheckoutTime(orderWork.getCheckoutTime());
//         esOrderPay.setAccountTime(orderWork.getAccountTime());
//         esOrderPay.setOrderCreater(orderWork.getCreater());
//     }
//
//     /**
//      * 组装工单详情数据
//      *
//      * @param orderDetailMap
//      * @param esOrderPay
//      */
//     private void processOrderDetail(Map<Long, EsOrderDetailVO> orderDetailMap, EsOrderPay esOrderPay) {
//         EsOrderDetailVO orderDetail = orderDetailMap.get(esOrderPay.getOrderId());
//
//         esOrderPay.setServCategName(orderDetail.getServCategName());
//         esOrderPay.setProductInfo(orderDetail.getProductInfo());
//         esOrderPay.setCityName(orderDetail.getCityName());
//         esOrderPay.setProvinceId(orderDetail.getProvinceId());
//         esOrderPay.setProvinceName(orderDetail.getProvinceName());
//     }
//
// }
